#if not defined _ur_defs_included
#include "ur_defs"
#endif

#define _ur_help_included 1

enum MENU_INFO {
	MI_RULES = 1,
	MI_RANKS,
	MI_BADGES
}
public showMenu(id){
	if(!get_pcvar_num(CvarActive))
		return PLUGIN_CONTINUE;
		
	new title[64];
	formatex(title, charsmax(title), "Ultra Rank Mod");
	new menu  = menu_create(title, "menuHandler");
	new info[2];
	
	formatex(title, charsmax(title), "%L", id, "HELP_RULES");
	info[0] = MI_RULES;
	menu_additem(menu, title, info);
	
	formatex(title, charsmax(title), "%L", id, "HELP_RANKS");
	info[0] = MI_RANKS;
	menu_additem(menu, title, info);
	
	formatex(title, charsmax(title), "%L", id, "HELP_BADGES");
	info[0] = MI_BADGES;
	menu_additem(menu, title, info);
	
	menu_display(id, menu);
	return PLUGIN_HANDLED;
}

public menuHandler(id, menu, item){
	if(item == MENU_EXIT){
		menu_destroy(menu);
		return PLUGIN_HANDLED;
	}
	new info[2];
	new acc, call;
	menu_item_getinfo(menu, item, acc, info, 1, _, _, call);
	new itemId = item[0];
	
	switch(itemId){
		case MI_RULES: saidRules(id);
		case MI_RANKS: saidRanks(id);
		case MI_BADGES: saidBadges(id);
	}
}

public saidRules(id){
	if(!get_pcvar_num(CVarActive))
		return PLUGIN_CONTINUE;
		
	new motd[3000];
	new tmp;
	format(motd, charsmax(motd),"<html><body bgcolor=aqua><center><tbody><font color=red><h1>Ultra Rank Mod</h1></font></center>");
	format(motd, charsmax(motd),"%s<font color=black><h2>%L</h2><ul>",motd, id, "YOU_GET");
	tmp=get_pcvar_num(CVarKillXp);
	if(tmp)
		format(motd, charsmax(motd),"%s<li>%L</li>",motd, id, "XP_FOR_KILL", tmp);
	
	tmp=get_pcvar_num(CVarHeadXp);
	if(tmp)
		format(motd, charsmax(motd),"%s<li>%L</li>",motd, id, "XP_FOR_HS", tmp);
	
	tmp=get_pcvar_num(CVarBombAddXp);
	if(tmp)	
		format(motd, charsmax(motd),"%s<li>%L</li>",motd, id, "XP_BOMB_ADD", tmp);
	
	tmp=get_pcvar_num(CVarHigherRankKillXp);
	if(tmp)	
		format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_HIGHER_RANK_KILL", tmp);
		
	tmp=get_pcvar_num(CVarLastManWinXp);
	if(tmp)	{
		format(motd, charsmax(motd),"%s<li>%L</li>",motd, id, "XP_LAST_MAN_WIN", tmp);
		tmp=get_pcvar_num(CVarLastManWinMinOpponents);
		if(tmp)
			format(motd, charsmax(motd),"%s^n%L",motd, id, "XP_LAST_MAN_MIN_OPONENTS");
	}
	
	tmp=get_pcvar_num(CVarRoundWinDeadXp);
	if(tmp)	
		format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_ROUND_WIN_DEAD", tmp);

	
	tmp=get_pcvar_num(CVarRoundWinLiveXp);
	if(tmp)	
		format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_ROUND_WIN_LIVE", tmp);
	
	if(get_pcvar_num(CVarVip)){	
		tmp=get_pcvar_num(CVarVipKillXp);
		if(tmp)	
			format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_VIP_KILL", tmp);
	}
	
	tmp=get_pcvar_num(CVarHostRescueXp);
	if(tmp)	
		format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_HOST_RESCUE", tmp);
	
	if(get_pcvar_num(CVarMedals)) {
		tmp=get_pcvar_num(CVarMedalBronzeXp);
		if(tmp)	
			format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_BRONZE", tmp);
		
		tmp=get_pcvar_num(CVarMedalSilverXp);
		if(tmp)	
			format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_SILVER", tmp);
		
		tmp=get_pcvar_num(CVarMedalGoldXp);
		if(tmp)	
			format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_GOLD", tmp);
	}
	if(get_pcvar_num(CVarDelXp) ){
		format(motd, charsmax(motd),"%s</ul><h2>%L</h2><ul>", motd, id, "YOU_LOOSE");
		
		tmp=get_pcvar_num(CvarDeathXp);
		if(tmp)	
			format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_DEATH", tmp);
			
		tmp=get_pcvar_num(CVarBombDelXp);
		if(tmp)	{
			format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_BOMB_DEL", tmp);
			if(get_pcvar_num(CVarBombDelXpOnlyLive)){
				format(motd, charsmax(motd),"%s^n%L", motd, id, "XP_BOMB_DEL_ONLY_LIVE");
			} else {
				format(motd, charsmax(motd),"%s^n%L", motd, id, "XP_BOMB_DEL_ALL");
			}
		}
		
		tmp=get_pcvar_num(CVarLowerRankKillXp);
		if(tmp)	
			format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_LOWER_KILL", tmp);
		
		tmp=get_pcvar_num(CVarRoundLooseXp);
		if(tmp)	
			format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_LOOSE", tmp);
		
		tmp=get_pcvar_num(CVarSuacideXp);
		if(tmp)	
			format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_SUACIDE", tmp);
		
		tmp=get_pcvar_num(CVarHostKillXp);
		if(tmp)	
			format(motd, charsmax(motd),"%s<li>%L</li>", motd, id, "XP_HOST_KILL", tmp);
	}
	format(motd, charsmax(motd),"%s</ul></font></tbody></body></html>", motd);
	show_motd(id, motd);
	
	return PLUGIN_HANDLED;
}

public saidRanks(id){
	if(!get_pcvar_num(CVarActive))
		return PLUGIN_CONTINUE;
		
	new motd[3000];
	format(motd, charsmax(motd),"<html><body bgcolor=black><center><tbody><font color=red><h1>Ultra Rank Mod</h1></font></center>");
	
	//You start as a Private
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_OLDER_PRIVATE", RankLevel[RANK_OLDER_PRIVATE]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_FIRST_CLASS_PRIVATE", RankLevel[RANK_FIRST_CLASS_PRIVATE]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_SPECJALIST", RankLevel[RANK_SPECJALIST]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_CORPORAL", RankLevel[RANK_CORPORAL]);
	
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_SERGEANT", RankLevel[RANK_SERGEANT]);	
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_STAFF_SERGEANT", RankLevel[RANK_STAFF_SERGEANT]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_SERGEANT_FIRST_CLASS", RankLevel[RANK_SERGEANT_FIRST_CLASS]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_MASTER_SERGEANT", RankLevel[RANK_MASTER_SERGEANT]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_FIRST_SERGEANT", RankLevel[RANK_FIRST_SERGEANT]);
	
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_SERGEANT_MAJOR", RankLevel[RANK_SERGEANT_MAJOR]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_COMMAND_SERGEANT_MAJOR", RankLevel[RANK_COMMAND_SERGEANT_MAJOR]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_SERGEANT_MAJOR_OF_THE_ARMY", RankLevel[RANK_SERGEANT_MAJOR_OF_THE_ARMY]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_SECOND_LIEUTENANT", RankLevel[RANK_SECOND_LIEUTENANT]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_FIRST_LIEUTENANT", RankLevel[RANK_FIRST_LIEUTENANT]);
	
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_CAPTAIN", RankLevel[RANK_CAPTAIN]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_MAJOR", RankLevel[RANK_MAJOR]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_LIEUTENANT_COLONEL", RankLevel[RANK_LIEUTENANT_COLONEL]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_COLONEL", RankLevel[RANK_COLONEL]);
	format(motd, charsmax(motd), MOTD1, motd, id, "RANK_BRIDAGIER_GENERAL", RankLevel[RANK_BRIDAGIER_GENERAL]);
	
	format(motd, charsmax(motd), MOTD2, motd, id, "RANK_MAJOR_GENERAL", RankLevel[RANK_MAJOR_GENERAL], id, "ALL_WEAPON_BADGES_EXPERT" );	
	format(motd, charsmax(motd), MOTD2, motd, id, "RANK_LIEUTENANT_GENERAL", RankLevel[RANK_LIEUTENANT_GENERAL], id, "ALL_WEAPON_BADGES_HITMAN");
	format(motd, charsmax(motd), MOTD2, motd, id, "RANK_GENERAL", RankLevel[RANK_GENERAL], id, "ALL_WEAPON_BADGES_OWNER");
	format(motd, charsmax(motd), MOTD2, motd, id, "RANK_GENERAL_OF_THE_ARMY", RankLevel[RANK_GENERAL_OF_THE_ARMY], id, "BEST_ON_SERWER");
	format(motd, charsmax(motd),"%s</tbody></body></html>", motd);
	show_motd(id, motd);
	return PLUGIN_HANDLED;
}

public saidBadges(id){
	if(!get_pcvar_num(CVarActive))
		return PLUGIN_CONTINUE;
	new title[64];
	formatex(title, charsmax(title), "%L", id, "MENU_BADGE_REQ");
	new menu = menu_create(title, "badgesHandler");
	new info[2];
	for(new w=WEAPONS_P228;w<=WEAPONS_P90;w++){
		copy(title, charsmax(title), WeaponNamesShort[w]);
		if(title[0]){
			info[0] = w;
			menu_additem(menu, title, info);
		}
	}
	menu_display(id, menu);
	return PLUGIN_HANDLED;

}

public badgesHandler(id, menu, item){
	if(item == MENU_EXIT){
		menu_destroy(menu);
		return PLUGIN_HANDLED;
	}
	if(item != MENU_BACK && item != MENU_MORE){
		new info[2];
		new acc,call;
		menu_item_getinfo(menu, item, acc,info, 1,_,_,call);
		menu_destroy(menu);
		showBadgesReqForWeapon(id, info[0]);
	}
	return PLUGIN_HANDLED;
}

stock showBadgesReqForWeapon(id, weapon){
	new motd[1500];
	format(motd, charsmax(motd),"<html><body bgcolor=aqua><center><tbody><font color=red><h1>Ultra Rank Mod</h1></font></center>");
	format(motd, charsmax(motd),"%s<font color=black><h2>%L</h2><table border=^"1^">",motd, id, "BADGES_REQ", WeaponNamesShort[weapon]);
	format(motd, charsmax(motd),"%s<tr><th>%L</th><th>%L</th><th>%L</th>",motd, id, "LEVEL", id, "KILLS_IN_ROUND",  id, "HS_IN_ROUND");
	format(motd, charsmax(motd),"%s<th>%L</th><th>%L</th>",motd, id, "KILLS_IN_MAP",  id, "HS_IN_MAP");
	format(motd, charsmax(motd),"%s<th>%L</th><th>%L</th></tr>",motd, id, "KILLS_TOTAL",  id, "HS_TOTAL");
	
	new badgeName[32];
	for(new b=BADGE_BEGINNER;b<=BADGE_OWNER;b++){
		getBadgeName(id, b, badgeName, charsmax(badgeName));
		format(motd, charsmax(motd),MOTD3,motd,  badgeName,  
			WEAPON_BADGE_LEVEL[weapon][b][LEVEL_KILLS_ROUND],
			WEAPON_BADGE_LEVEL[weapon][b][LEVEL_HS_ROUND],
			WEAPON_BADGE_LEVEL[weapon][b][LEVEL_KILLS_MAP],
			WEAPON_BADGE_LEVEL[weapon][b][LEVEL_HS_MAP],
			WEAPON_BADGE_LEVEL[weapon][b][LEVEL_KILLS_TOTAL],
			WEAPON_BADGE_LEVEL[weapon][b][LEVEL_HS_TOTAL]);						
	}
	format(motd, charsmax(motd),"%s</table></font></tbody></body></html>");
	show_motd(id, motd);
	showBadgesReq(id);
}

stock getBadgeName(id, badge,name[], len){
	switch(badge) {
		case BADGE_BEGINNER:formatex(name, len, "%L", id, "BADGE_BEGINNER");
		case BADGE_BASIC:formatex(name, len, "%L", id, "BADGE_BASIC");
		case BADGE_ADVANCED:formatex(name, len, "%L", id, "BADGE_ADVANCED");
		case BADGE_VETERAN:formatex(name, len, "%L", id, "BADGE_VETERAN");
		case BADGE_EXPERT:formatex(name, len, "%L", id, "BADGE_EXPERT");
		case BADGE_HITMAN:formatex(name, len, "%L", id, "BADGE_HITMAN");
		case BADGE_OWNER:formatex(name, len, "%L", id, "BADGE_OWNER");
	}
}
